//
//  BaseDataTool.m
//
//  Created by Northwan on 15/4/14.
//  Copyright (c) 2015年  All rights reserved.
//

#import "BaseDataTool.h"
#import "BaseHttpTool.h"

@implementation BaseDataTool

+ (void)getWithUrl:(NSString *)url param:(NSDictionary *)param resultClass:(Class)resultClass success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    [BaseHttpTool get:url params:param success:^(id responseObj) {
        if (success) {
            NSLog(@"%@:%@",resultClass,[[NSString alloc]initWithData:responseObj encoding:NSUTF8StringEncoding]);
            id result = [resultClass objectWithJSONData:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)postWithUrl:(NSString *)url param:(NSDictionary *)param resultClass:(Class)resultClass success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    [BaseHttpTool post:url params:param success:^(id responseObj) {
        if (success) {
            NSLog(@"%@:%@",resultClass,[[NSString alloc]initWithData:responseObj encoding:NSUTF8StringEncoding]);
            id result = [resultClass objectWithJSONData:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

@end
